accountingIntegrationDashboardApp.controller('maintenanceStoreTransactionCtrl', ['$scope', '$http', '$log', 'serverDataService','commonValidationService', function ($scope, $http, $log, serverDataService, commonValidationService){ 


    $scope.transactions = [];
    $scope.stores = [];
    
    $scope.entityName = 'store-transaction';
    
    $scope.setChildScope($scope);
    $scope.renderRecordsFromServer();
    

    $scope.loadTransactions = function(){
        return $scope.transactions.length ? null : serverDataService.getEntityList('transaction', false)
                .then(function (data){
                    $scope.transactions = data.gridRecords;
                });
    };


    $scope.loadStores = function(){
        return $scope.stores.length ? null : serverDataService.getEntityList('store', false)
                .then(function (data){
                    $scope.stores = data.gridRecords;
                });
    };


    $scope.addStoreTransaction = function() {
        $scope.inserted = {
          id: null,
          transaction: null,
          store: null
        };
        $scope.gridRecords.push($scope.inserted);
    };

    
    $scope.validateStoreCode = function (columnName, data){
    	$scope.validateCodeMsg = null;
    	msg = commonValidationService.checkNotEmpty(columnName, data);
    	if (msg) {return msg;}
    };
    
    $scope.validateTransactionCode = function (columnName, data){
    	$scope.validateCodeMsg = null;
    	msg = commonValidationService.checkNotEmpty(columnName, data);
    	if (msg) {return msg;}
    	msg = commonValidationService.checkNumbersOnly(columnName, data);
    	if (msg) {return msg;}
    };            
}]);